﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WebUtils
{
    public class Parameter
    {
        public string Key { get; set; }
        public string Value { get; set; }
    }
    /// <summary>
    /// represents a paremeter, that is, a string key and a string value
    /// </summary>
    public class UnEncodedURLParameter : Parameter, IComparable<UnEncodedURLParameter>
    {

        public override bool Equals(object obj)
        {
            var that = (UnEncodedURLParameter)obj;
            if (that == null)
                return false;

            return that.Key == this.Key && that.Value == this.Value;
        }

        public EncodedURLParameter Encode()
        {
            return new EncodedURLParameter()
            {
                Key = ParameterEncoder.ValueEncode(this.Key),
                Value = ParameterEncoder.ValueEncode(this.Value)
            };
        }

        public int CompareTo(UnEncodedURLParameter other)
        {
            return this.Key.CompareTo(other.Key) * 10
                 + this.Value.CompareTo(other.Value);
        }
    }

    public class EncodedURLParameter 
    {
        public string Key { get; set; }
        public string Value { get; set; }

        public override bool Equals(object obj)
        {
            var that = (EncodedURLParameter)obj;
            if (that == null)
                return false;

            return that.Key == this.Key && that.Value == this.Value;
        }


        public UnEncodedURLParameter Decode()
        {
            return new UnEncodedURLParameter()
            {
                Key = ParameterEncoder.ValueDecode(this.Key),
                Value = ParameterEncoder.ValueDecode(this.Value)
            };
        }
    }
}
